package modelTest;

import static org.junit.Assert.*;
import model.Bidder;
import model.Item;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests the Item class
 * 
 * @author Daniel Bartholomew
 */
public class BidderTest {
	
	private String testName = "Anonymous Bidder";
	
	private Bidder testBidder;
	
	private String testItemName = "TestItem";
	
	private double testPrice = 50;
	
	private String testNotes = "Not very interesting";
	
	private Item testItem;
	
	@Before
	public void initialize() {
		testBidder = new Bidder(testName);
		testItem = new Item(testItemName, testPrice, testNotes);
	}
	
	@Test
	public void testBidderCreation() {
		assertEquals("Name Test", testName, testBidder.getName());
		assertTrue("Test for empty Bids", testBidder.getBids().isEmpty());
	}
	
	@Test
	public void testIDs() {
		int startingID = testBidder.getID();

		Bidder testBidder1 = new Bidder(testName);
		Bidder testBidder2 = new Bidder(testName);
		Bidder testBidder3 = new Bidder(testName);
		
		assertEquals("ID Test 1", startingID + 1, testBidder1.getID());
		assertEquals("ID Test 2", startingID + 2, testBidder2.getID());
		assertEquals("ID Test 3", startingID + 3, testBidder3.getID());
	}

	@Test
	public void testNewBidLowPrice() {
		assertFalse("Price too low", testBidder.newBid(testItem, testPrice - 1));
		assertEquals("No valid bid", null, testBidder.getBids().get(testItem));
	}

	@Test
	public void testNewBidEqualPrice() {
		assertTrue("Price equal", testBidder.newBid(testItem, testPrice));
		assertEquals("Valid Bid", (Double) testPrice, (Double) testBidder.getBids().get(testItem));
	}

	@Test
	public void testNewBidHighPrice() {
		assertTrue("Price higher", testBidder.newBid(testItem, testPrice + 10));
		assertEquals("Valid Bid", (Double) (testPrice + 10), (Double) testBidder.getBids().get(testItem));
	}

	@Test
	public void testNewBidMultiple() {
		assertTrue("First Bid", testBidder.newBid(testItem, testPrice));
		assertEquals("Valid Bid", (Double) testPrice, (Double) testBidder.getBids().get(testItem));
		assertTrue("Bid on duplicate item", testBidder.newBid(testItem, testPrice + 10));
		assertEquals("Valid Bid", (Double) (testPrice + 10), (Double) testBidder.getBids().get(testItem));
	}
}
